<template>
  <div id="app">
    <h2>测试题</h2>
    <subject v-for="(item, id) in 5" :key="id">
      <SubjectItem @check="check"></SubjectItem>
    </subject>
    <div>
      <flag>
        <Flagltem></Flagltem>
      </flag>
    </div>
  </div>
</template>

<script>
import SubjectItem from "./components/SubjectItem.vue";
import Flagltem from "./components/FlagItem.vue";
export default {
  data() {
    return {
      txt: [],
    };
  },
  components: {
    SubjectItem,
    Flagltem,
  },
  methods: {
    check(msg) {
      alert(msg);

      // 检查 msg 是否已存在于 this.txt 中
      if (!this.txt.includes(msg)) {
        // 过滤掉与 msg 相同的元素
        const filteredTxt = this.txt.filter((item) => item !== msg);
        // 添加新的 msg
        filteredTxt.push(msg);
        // 更新 this.txt
        this.txt = filteredTxt;
      } else {
        console.log("msg already exists in this.txt");
      }
    },
  },
  mounted() {},
};
</script>

<style>
body {
  background-color: #eee;
}

#app {
  background-color: #fff;
  width: 500px;
  margin: 50px auto;
  box-shadow: 3px 3px 3px rgba(0, 0, 0, 0.5);
  padding: 2em;
}
</style>
